package test;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper;
import org.wltea.analyzer.lucene.IKAnalyzer;

import com.ld.zxw.config.Config;
import com.ld.zxw.core.LucenePlugin;
/**
 * config
 * @author zxw
 *
 */
public class DemoConfig{
	
	/**
	 * 以下是基础配置  开启动态词库 优先使用本地词库
	 */
	public void basicsConfig() {
		Config config = new Config();
		config.setLucenePath("d:/LuceneHome/core/ext/");
		
		
		//设置每个字段 独立的分词器 并且 设置默认分词器
		Map<String, Analyzer> analyzer = new HashMap<>();
		analyzer.put("name", new IKAnalyzer(false,config));
		analyzer.put("sex", new IKAnalyzer(false,config));
		config.setAnalyzer(new PerFieldAnalyzerWrapper(new IKAnalyzer(false,config), analyzer));
		//设置单个分词器
		config.setAnalyzer(new PerFieldAnalyzerWrapper(new IKAnalyzer(false,config)));
		
		
		
		
//		config.setHighlight(true);
		List<String> list = new ArrayList<>();
		list.add("content");
//		list.add("name");
		config.setParticipleField(list);
		config.setHighlightFields(list);
		
		Map<String, Float> boostField = new HashMap<>();
		boostField.put("name", 1.5f);
		config.setBoostField(boostField);
		
		LucenePlugin lucenePlugin = new LucenePlugin();
		lucenePlugin.putDataSource(config, "test");
		lucenePlugin.start();
	}
}
